package com.simoniu.first.servlet;

import com.simoniu.first.entity.Users;
import java.io.*;
import java.text.SimpleDateFormat;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.annotation.*;

@WebServlet(name = "RegServlet",value="/reg",loadOnStartup = 1)
public class RegServlet extends HttpServlet {

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            Users regUser = new Users();
            regUser.setUsername(request.getParameter("username"));
            regUser.setPassword(request.getParameter("password"));
            regUser.setEmail(request.getParameter("email"));
            regUser.setGender(request.getParameter("gender"));
            regUser.setSalary(Double.parseDouble(request.getParameter("salary")));
            regUser.setEducation(Integer.parseInt(request.getParameter("education")));
            regUser.setProvince(request.getParameter("province"));
            regUser.setBirthday(new SimpleDateFormat("yyyy-MM-dd").parse(request.getParameter("birthday")));
            //注意：字符串数组属性使用getParameterValues方法接收。
            regUser.setFavorites(request.getParameterValues("favorites"));
            regUser.setIntroduce(request.getParameter("introduce"));
            regUser.setAccept(Boolean.parseBoolean(request.getParameter("accept")));

            System.out.println("********注册用户资料*********");
            System.out.println(regUser);
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    public void destroy() {
    }
}